package com.way.Java多线程编程核心技术v2.chapter02_对象及变量的并发访问._2_1_synchronized同步方法.多个对象多个锁;

/**
 * @PROJECT_NAME: projects
 * @DESCRIPTION:
 * @USER: 魏彪
 * @DATE: 2023/11/27 15:51
 */
public class HasSelfPrivateNum {
    private int num = 0;

    synchronized public void addI(String username) {
        try {
            if ("a".equals(username)) {
                num = 100;
                System.out.println("a set over");
                Thread.sleep(2000);
            } else {
                num = 200;
                System.out.println("b set over");
            }
            System.out.println(username + " num = " + num);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}
